package com.eeepay.eeepay_v2.activity;

import android.view.View;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.eeepay.eeepay_v2.R;
import com.eeepay.eeepay_v2.adapter.GrabBisAdpater;
import com.eeepay.eeepay_v2.adapter.OrderResultAdapter;
import com.eeepay.eeepay_v2.model.GrabBisInfo;
import com.eeepay.eeepay_v2.model.OrderResult;
import com.eeepay.eeepay_v2.view.DeleteListView;
import com.eeepay.v2_library.ui.ABBaseActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Ching on 2016/3/18.
 * 抢占商机界面
 */
public class GrabBisActivity extends ABBaseActivity implements RadioGroup.OnCheckedChangeListener, DeleteListView.RemoveListener, View.OnClickListener {

    private RadioGroup radioGroup;
    private DeleteListView graBisLv;
    private TextView queryTv, backTv;
    private ListView orderLv;
    private List<GrabBisInfo> grablist;
    private List<OrderResult> orderList;

    private GrabBisAdpater grabAdapter;
    private OrderResultAdapter orderAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_grab_business;
    }

    @Override
    protected void initWidget() {

        radioGroup = getViewById(R.id.rg_grab_order);
        graBisLv = getViewById(R.id.lv_grab_bis);
        queryTv = getViewById(R.id.tv_grab_query);
        backTv = getViewById(R.id.tv_grab_back);
        orderLv = getViewById(R.id.lv_grab_order_result);
    }

    @Override
    protected void eventOnClick() {

        queryTv.setOnClickListener(this);
        backTv.setOnClickListener(this);

        radioGroup.setOnCheckedChangeListener(this);

        grablist = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            GrabBisInfo grab = new GrabBisInfo("超级快", "广东省深圳市", "订单编号：2019456648446");
            grablist.add(grab);
        }

        grabAdapter = new GrabBisAdpater(this);
        grabAdapter.addAll(grablist);
        graBisLv.setAdapter(grabAdapter);
        graBisLv.setRemoveListener(this);

        orderList = new ArrayList<>();
        for (int i = 0; i < 7; i++) {
            OrderResult order = new OrderResult("张三", "超级刷", "完成 " + i);
            orderList.add(order);
        }
        orderAdapter = new OrderResultAdapter(this);
        orderAdapter.addAll(orderList);
        orderLv.setAdapter(orderAdapter);

    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {

        switch (checkedId) {
            case R.id.rbtn_grab:
                graBisLv.setVisibility(View.VISIBLE);
                orderLv.setVisibility(View.GONE);
                break;
            case R.id.rbtn_order:
                graBisLv.setVisibility(View.GONE);
                orderLv.setVisibility(View.VISIBLE);
                break;
        }
    }


    @Override
    public void removeItem(DeleteListView.RemoveDirection direction, int position) {

        switch (direction) {
            case LEFT:
                grabAdapter.remove(position);
                Toast.makeText(this, "remove", Toast.LENGTH_SHORT).show();
                break;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_grab_query:
                goActivity(OrderQueryActivity.class);
                break;
            case R.id.tv_grab_back:
                finish();
                break;
        }
    }
}
